import './index.less';

import React from 'react';
import {observer, inject} from 'mobx-react';
import {WeaTop, WeaTab, WeaRightMenu,WeaLocaleProvider} from 'ecCom';
import {Row, Col} from 'antd';
import AdvanceSearch from './AdvanceSearch';
import AnalyseEchart from './AnalyseEchart';
import FlowAnalyseCount from '../report-public/flow-analyse-count/index';
import FlowReportDetail from '../report-public/flow-report-detail/index';
import ReportNoRight from '../report-public/report-no-right/index';
import * as ReportUtil from '../../../util/reportUtil';
const getLabel = WeaLocaleProvider.getLabel;

@inject('wfDoingAnalyseStore')
@observer
export default class Main extends React.Component {
    constructor(props) {
        super(props);

        const {wfDoingAnalyseStore} = props;
        const {initDatas} = wfDoingAnalyseStore;
        initDatas && initDatas();
    }

    componentWillUnmount() {
        const {reSet} = this.props.wfDoingAnalyseStore;
        reSet && reSet();
    }

    componentWillReceiveProps(nextProps) {
        if (this.props.location.key !== nextProps.location.key) {
            const {clearStatus, initDatas} = this.props.wfDoingAnalyseStore;
            clearStatus();
            initDatas();
        }
    }

    render() {
        const {wfDoingAnalyseStore} = this.props;
        const {loading = false, advanceSearchData = {}, advanceSearchPara = {}, analyseData = {}, modalParams = {}} = wfDoingAnalyseStore;
        const {updateAdvanceSearchPara, showModal, updateModalPara, closeModal} = wfDoingAnalyseStore; //action
        const {tabDatas = [], noRight = false, bottomInfo = ''} = advanceSearchData;
        const {echartDatas1 = {}, echartDatas2 = {}, countData = []} = analyseData;
        const {tabKey = 1} = advanceSearchPara;
        return (
            <div className="wf-doing-analyse">
                {noRight ?
                    <ReportNoRight ecId={`${this && this.props && this.props.ecId || ''}_ReportNoRight@ohn642`}/>
                    :
                    <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@zridpi`} loading={loading} icon={<i className='icon-coms-workflow'/>} buttons={[]}
                            iconBgcolor='#0079DE' title={getLabel(388257,'在办流程分析')} showDropIcon={false}>
                        <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@e4v7ln`} datas={tabDatas} keyParam={"key"} selectedKey={tabKey}
                                onChange={this.doChangeTab.bind(this)}/>
                        <AdvanceSearch ecId={`${this && this.props && this.props.ecId || ''}_AdvanceSearch@tqlnsa`} advanceSearchData={advanceSearchData} advanceSearchPara={advanceSearchPara}
                                       updateAdvanceSearchPara={updateAdvanceSearchPara} tabKey={tabKey}/>
                        <FlowAnalyseCount ecId={`${this && this.props && this.props.ecId || ''}_FlowAnalyseCount@d3n26x`} datas={countData} showDetailModal={showModal}/>
                        <div className="flow-doing-echart">
                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@yvxpec`}>
                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@2auhtj`} span={12}><AnalyseEchart ecId={`${this && this.props && this.props.ecId || ''}_AnalyseEchart@wttfpk`} loading={loading} eChartDatas={echartDatas1} module={1}
                                                              showModal={showModal}/></Col>
                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@1xhhze`} span={12}><AnalyseEchart ecId={`${this && this.props && this.props.ecId || ''}_AnalyseEchart@vwqr02`} loading={loading} eChartDatas={echartDatas2} module={2}
                                                              showModal={showModal}/></Col>
                            </Row>
                        </div>
                        <FlowReportDetail ecId={`${this && this.props && this.props.ecId || ''}_FlowReportDetail@g1knzk`} {...modalParams} updateModalPara={updateModalPara} closeModal={closeModal}/>
                        <div className='count-bottom'>{bottomInfo}</div>
                    </WeaTop>
                }
            </div>
        )
    }

    doChangeTab(tabKey) {
        const {wfDoingAnalyseStore} = this.props;
        const {updateAdvanceSearchPara, advanceSearchData, advanceSearchPara = {}} = wfDoingAnalyseStore;
        const {orgBrowserProps = []} = advanceSearchData;
        const updateInfo = {tabKey};
        let {orgtype} = advanceSearchPara;

        if (tabKey == 2) {
            if (orgtype > 3) orgtype = 3;
        } else if (tabKey == 3) {
            if (orgtype > 2) orgtype = 2;
        }
        updateInfo['orgtype'] = orgtype;

        //条件初始化
        updateInfo.datarange = 1;
        updateInfo.dataid = '';

        updateInfo.createdatetype = 1;
        updateInfo.createstartdate = '';
        updateInfo.createenddate = '';
        updateInfo.receivedatetype = 1;
        updateInfo.receivestartdate = '';
        updateInfo.receiveenddate = '';
        //获取默认值
        const {config = []} = advanceSearchData;
        if (orgtype > 1 && config.length > 0) {
            const {selectLinkageDatas = {}} = config[0];
            updateInfo['orgid'] = ReportUtil.getDefaultId(orgtype, selectLinkageDatas);
        }
        updateAdvanceSearchPara && updateAdvanceSearchPara(updateInfo);
    }
}
